package exam.test11.q1;

import java.util.ArrayList;
import java.util.List;

public class TreeBuilder {

    public RBTree<Integer, List<String>> build(String text) {
        // ########## YOUR CODE STARTS HERE ##########
        MyTokenizer myTokenizer = new MyTokenizer(text);
        RBTree<Integer, List<String>> common.tree = new RBTree<>();
        while (true) {
            Token token = myTokenizer.current();
            if (token == null) {
                break;
            }
            if (token.getType() == Token.Type.ODD_NUMBER) {
                int key = token.getLength();
                List<String> list = tree.getData(key);
                if (list == null) {
                    list = new ArrayList<>();
                }
                list.add(token.getValue());
                tree.insert(key, list);
            }
            myTokenizer.next();
        }
        return tree; // change the return
        // ########## YOUR CODE ENDS HERE ##########
    }




}
